package cn.com.tctec.faked;

import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * 一条状态记录
 */
public class RunStatusDatum {

    private SimpleDateFormat datetimeFormat = new SimpleDateFormat(Constant.DATETIME_FMT);

    private String tagF;
    private Integer value;
    private Long timeInSecond;

    public RunStatusDatum(String tagF, Integer value, Long timeInSecond) {
        super();
        this.tagF = tagF;
        this.value = value;
        this.timeInSecond = timeInSecond;
    }

    /**
     * 该条记录插入 influx db 的脚本
     * @return 插入脚本
     */
    public String geneInfluxInsertString() {

        String template = "%s,%s=%s %s=%d %d";
        String ins = String.format(template,
                Constant.InfluxDB.HIS_MEASUREMENT＿NAME,
                Constant.InfluxDB.HIS_MEASUREMENT_TAG_KEY, this.tagF,
                Constant.InfluxDB.HIS_MEASUREMENT_VALUE＿FIELD＿NAME, this.value,
                this.timeInSecond * 1000 * 1000 * 1000);
        System.out.println(ins);
        return ins;
    }

    @Override
    public String toString() {
        return String.format("RunStatusDatum [tagF=%s, value=%s, time=%s]",
                tagF,
                value,
                datetimeFormat.format(new Date(this.timeInSecond * 1000)));
    }
}
